import { PrismaClient } from '@prisma/client'

// 创建 Prisma 客户端实例
export const prisma = new PrismaClient({
    log: ['query', 'info', 'warn', 'error']
})

// 连接数据库
export async function connectDatabase() {
    try {
        await prisma.$connect()
        console.log('[INFO] ✅ Database connected successfully')
    } catch (error) {
        console.error('[ERROR] ❌ Database connection failed:', error)
        throw error
    }
}

// 断开数据库连接
export async function disconnectDatabase() {
    try {
        await prisma.$disconnect()
        console.log('[INFO] ✅ Database disconnected successfully')
    } catch (error) {
        console.error('[ERROR] ❌ Database disconnection failed:', error)
        throw error
    }
}